package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.PerformanceBonus;
import com.amsp.oa.oademo.service.PerformanceBonusService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/performance-bonus")
@Tag(name = "绩效奖金申请管理")
@CrossOrigin
public class PerformanceBonusController {

    @Autowired
    private PerformanceBonusService performanceBonusService;

    @GetMapping("/list")
    @Operation(summary = "获取绩效奖金申请列表")
    public IPage<PerformanceBonus> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String applicant,
            @RequestParam(required = false) String department,
            @RequestParam(required = false) String position,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate) {

        return performanceBonusService.getPage(current, size, applicant, department, position, startDate, endDate);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取绩效奖金申请详情")
    public PerformanceBonus getById(@PathVariable Long id) {
        return performanceBonusService.getById(id);
    }

    @PostMapping("/save")
    @Operation(summary = "保存绩效奖金申请")
    public boolean save(@RequestBody PerformanceBonus performanceBonus) {
        if (performanceBonus.getId() != null) {
            return performanceBonusService.updateById(performanceBonus);
        }
        return performanceBonusService.save(performanceBonus);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除绩效奖金申请")
    public boolean delete(@PathVariable Long id) {
        return performanceBonusService.removeById(id);
    }
}